package com.github.chain.admin.api.config;

import com.github.chain.admin.api.handler.AdminLoggerHandler;
import com.github.chain.admin.api.resolver.MyLocaleResolver;
import com.github.framework.core.spring.SpringContextUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class AdminMvcConfig implements WebMvcConfigurer {

    @Resource
    private AdminLoggerHandler adminLoggerHandler;

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    @Bean
    public SpringContextUtils springContextUtils(){
        return new SpringContextUtils();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminLoggerHandler)
                .excludePathPatterns("/login")
                .excludePathPatterns("/captcha")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/images/**")
                .excludePathPatterns("/lib/**")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/**/system/actionLog/**")
                .excludePathPatterns("/js/**");
    }
}
